using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace RideMe.CommandManagement
{
    public class CommandInstanceCollection : System.Collections.CollectionBase
    {
        internal CommandInstanceCollection(Command cmd)
            : base()
        {
            command = cmd;
        }

        private Command command;

        public void Add(object instance)
        {
            if (instance != null)
            {
                this.List.Add(instance);
            }
        }

        public void Add(object[] items)
        {
            if (items != null)
            {
                foreach (object item in items)
                {
                    this.Add(item);
                }
            }
        }

        public void Remove(object value)
        {
            this.List.Remove(value);
        }

        public void CopyTo(System.Array array, int index)
        {
            this.List.CopyTo(array, index);
        }

        public void Insert(int index, object value)
        {
            this.List.Insert(index, value);
        }

        public int IndexOf(object value)
        {
            return this.List.IndexOf(value);
        }

        public object this[int index]
        {
            get
            {
                return this.List[index];
            }
        }

        protected override void OnInsertComplete(int index, object value)
        {
            command.Manager.GetCommandExecutor(value).InstanceAdded(value, command);
        }
    }
}
